const express = require('express');
const router = express.Router();
const { protect } = require('../middlewares/authMiddleware');
const {
  sendMessage,
  sendPost,
  sendEmoji,
  getChatHistory
} = require('../controllers/chatController');

/**
 * @swagger
 * /chat/message:
 *   post:
 *     summary: 发送消息
 *     tags: [Chat]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               receiverId:
 *                 type: string
 *               message:
 *                 type: string
 *     responses:
 *       201:
 *         description: 消息发送成功
 *       500:
 *         description: 发送消息失败
 */
router.post('/message', protect, sendMessage);

/**
 * @swagger
 * /chat/post:
 *   post:
 *     summary: 发送帖子
 *     tags: [Chat]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               receiverId:
 *                 type: string
 *               postId:
 *                 type: string
 *     responses:
 *       201:
 *         description: 帖子发送成功
 *       404:
 *         description: 帖子未找到
 *       500:
 *         description: 发送帖子失败
 */
router.post('/post', protect, sendPost);

/**
 * @swagger
 * /chat/emoji:
 *   post:
 *     summary: 发送表情
 *     tags: [Chat]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               receiverId:
 *                 type: string
 *               emoji:
 *                 type: string
 *     responses:
 *       201:
 *         description: 表情发送成功
 *       500:
 *         description: 发送表情失败
 */
router.post('/emoji', protect, sendEmoji);

/**
 * @swagger
 * /chat/{userId}:
 *   get:
 *     summary: 获取聊天历史
 *     tags: [Chat]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: userId
 *         schema:
 *           type: string
 *         required: true
 *         description: 对方用户ID
 *     responses:
 *       200:
 *         description: 聊天历史获取成功
 *       500:
 *         description: 获取聊天历史失败
 */
router.get('/:userId', protect, getChatHistory);

module.exports = router;